package com.zxmr.domain.service;

import java.sql.SQLException;
import java.util.List;

import com.zxmr.CommonInit;
import com.zxmr.db.DBManager;
import com.zxmr.domain.Contract;

public class ContractService {

	DBManager db = CommonInit.getDBManager();
	
	public boolean addContract(Contract contract)
	{
		try {
			db.getMapper().insert("contract.add",contract);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	public Contract queryContract(int id,int company)
	{
		try
		{
			Contract c = new Contract();
			c.setCompany(company);
			c.setId(id);
			return (Contract)db.getMapper().queryForObject("contract.queryByID",c);
		}catch(SQLException e){
			e.printStackTrace();
		}
		return null;
	}
	public boolean updateContract(Contract contract)
	{
		try {
			db.getMapper().update("contract.update", contract);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	@SuppressWarnings("unchecked")
	public List<Contract> queryContractPagination(ContractSearchBean bean)
	{
		try {
			return (List<Contract>)db.getMapper().queryForList("contract.searchPagination", bean);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	public int queryContractPaginationCount(ContractSearchBean bean)
	{
		try {
			return (Integer)db.getMapper().queryForObject("contract.findCountPagination", bean);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return -1;
	}
}
